package com.dycx.api.controller.manage.cms;

import com.dycx.cms.dto.ArticleDTO;
import com.dycx.cms.service.ArticleService;
import com.dycx.common.RestResponse;
import com.dycx.common.annotation.WriterLog;
import com.dycx.common.enums.BizTypeEnum;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

@RestController
@RequestMapping(value = "/manage/cms/article")
public class ArticleController {

    @Resource
    private ArticleService articleService;

    /**
     * 添加
     **/
    @WriterLog(bizType = BizTypeEnum.CMS_ARTICLE, bizValue = "{#articleDto.id}",logTitle = "添加文章")
    @PostMapping("/add")
    public RestResponse<?> add(@RequestBody @Valid ArticleDTO articleDto) {
        return articleService.add(articleDto) ? RestResponse.success() : RestResponse.fail();
    }

    /**
     * 修改
     **/
    @WriterLog(bizType = BizTypeEnum.CMS_ARTICLE, bizValue = "{#articleDto.id}",logTitle = "修改文章")
    @PostMapping("/edit")
    public RestResponse<?> edit(@RequestBody @Valid ArticleDTO articleDto) {
        return articleService.edit(articleDto) ? RestResponse.success() : RestResponse.fail();
    }

    /**
     * 刪除
     **/
    @WriterLog(bizType = BizTypeEnum.CMS_ARTICLE, bizValue = "{#id}",logTitle = "删除文章")
    @GetMapping("/delete")
    public RestResponse<?> delete(int id) {
        return articleService.delete(id) ? RestResponse.success() : RestResponse.fail();
    }

    /**
     * 分页
     **/
    @PostMapping("/getPage")
    public RestResponse<?> getPage(@RequestBody ArticleDTO articleDto) {
        return RestResponse.success(articleService.getPage(articleDto));
    }

    /**
     * 查询详细
     **/
    @GetMapping("/getDetailById")
    public RestResponse<?> getDetailById(int id) {
        return RestResponse.success(articleService.getDetailById(id, null));
    }


}
